#pragma once
#include <iostream>
#include <functional>

class Defer
{
public:
    Defer(std::function<void()> f) : f_(f) {}
    ~Defer() { f_(); }

private:
    std::function<void()> f_;
};

#define DEFER(x) Defer defer_##__LINE__(x)